home *** CD-ROM | disk | FTP | other *** search
/ Spidla DivX / DivX.bin / FLAC 1.1.0 / include / FLAC++ / metadata.h < prev   
Encoding:
C/C++ Source or Header  |  2003-01-22  |  33.9 KB  |  942 lines

  1. /* libFLAC++ - Free Lossless Audio Codec library
  2.  * Copyright (C) 2002,2003  Josh Coalson
  3.  *
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Library General Public
  6.  * License as published by the Free Software Foundation; either
  7.  * version 2 of the License, or (at your option) any later version.
  8.  *
  9.  * This library is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.  * Library General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Library General Public
  15.  * License along with this library; if not, write to the
  16.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.  * Boston, MA  02111-1307, USA.
  18.  */
  19.  
  20. #ifndef FLACPP__METADATA_H
  21. #define FLACPP__METADATA_H
  22.  
  23. #include "export.h"
  24.  
  25. #include "FLAC/metadata.h"
  26.  
  27. // ===============================================================
  28. //
  29. //  Full documentation for the metadata interface can be found
  30. //  in the C layer in include/FLAC/metadata.h
  31. //
  32. // ===============================================================
  33.  
  34. /** \file include/FLAC++/metadata.h
  35.  *
  36.  *  \brief
  37.  *  This module provides classes for creating and manipulating FLAC
  38.  *  metadata blocks in memory, and three progressively more powerful
  39.  *  interfaces for traversing and editing metadata in FLAC files.
  40.  *
  41.  *  See the detailed documentation for each interface in the
  42.  *  \link flacpp_metadata metadata \endlink module.
  43.  */
  44.  
  45. /** \defgroup flacpp_metadata FLAC++/metadata.h: metadata interfaces
  46.  *  \ingroup flacpp
  47.  *
  48.  *  \brief
  49.  *  This module provides classes for creating and manipulating FLAC
  50.  *  metadata blocks in memory, and three progressively more powerful
  51.  *  interfaces for traversing and editing metadata in FLAC files.
  52.  *
  53.  *  The behavior closely mimics the C layer interface; be sure to read
  54.  *  the detailed description of the
  55.  *  \link flac_metadata C metadata module \endlink.
  56.  */
  57.  
  58.  
  59. namespace FLAC {
  60.     namespace Metadata {
  61.  
  62.         // ============================================================
  63.         //
  64.         //  Metadata objects
  65.         //
  66.         // ============================================================
  67.  
  68.         /** \defgroup flacpp_metadata_object FLAC++/metadata.h: metadata object classes
  69.          *  \ingroup flacpp_metadata
  70.          *
  71.          * This module contains classes representing FLAC metadata
  72.          * blocks in memory.
  73.          *
  74.          * The behavior closely mimics the C layer interface; be
  75.          * sure to read the detailed description of the
  76.          * \link flac_metadata_object C metadata object module \endlink.
  77.          *
  78.          * Any time a metadata object is constructed or assigned, you
  79.          * should check is_valid() to make sure the underlying
  80.          * ::FLAC__StreamMetadata object was able to be created.
  81.          *
  82.          * \warning
  83.          * When the get_*() methods of any metadata object method
  84.          * return you a const pointer, DO NOT disobey and write into it.
  85.          * Always use the set_*() methods.
  86.          *
  87.          * \{
  88.          */
  89.  
  90.         /** Base class for all metadata block types.
  91.          */
  92.         class FLACPP_API Prototype {
  93.         protected:
  94.             //@{
  95.             /** Constructs a copy of the given object.  This form
  96.              *  always performs a deep copy.
  97.              */
  98.             Prototype(const Prototype &);
  99.             Prototype(const ::FLAC__StreamMetadata &);
  100.             Prototype(const ::FLAC__StreamMetadata *);
  101.             //@}
  102.  
  103.             /** Constructs an object with copy control.  When \a copy
  104.              *  is \c true, behaves identically to
  105.              *  FLAC::Metadata::Prototype::Prototype(const ::FLAC__StreamMetadata *object).
  106.              *  When \a copy is \c false, the instance takes ownership of
  107.              *  the pointer and the ::FLAC__StreamMetadata object will
  108.              *  be freed by the destructor.
  109.              *
  110.              *  \assert
  111.              *    \code object != NULL \endcode
  112.              */
  113.             Prototype(::FLAC__StreamMetadata *object, bool copy);
  114.  
  115.             //@{
  116.             /** Assign from another object.  Always performs a deep copy. */
  117.             void operator=(const Prototype &);
  118.             void operator=(const ::FLAC__StreamMetadata &);
  119.             void operator=(const ::FLAC__StreamMetadata *);
  120.             //@}
  121.  
  122.             /** Deletes the underlying ::FLAC__StreamMetadata object.
  123.              */
  124.             virtual void clear();
  125.  
  126.             ::FLAC__StreamMetadata *object_;
  127.         public:
  128.             /** Deletes the underlying ::FLAC__StreamMetadata object.
  129.              */
  130.             virtual ~Prototype();
  131.  
  132.             //@{
  133.             /** Check for equality, performing a deep compare by following pointers. */
  134.             inline bool operator==(const Prototype &) const;
  135.             inline bool operator==(const ::FLAC__StreamMetadata &) const;
  136.             inline bool operator==(const ::FLAC__StreamMetadata *) const;
  137.             //@}
  138.  
  139.             //@{
  140.             /** Check for inequality, performing a deep compare by following pointers. */
  141.             inline bool operator!=(const Prototype &) const;
  142.             inline bool operator!=(const ::FLAC__StreamMetadata &) const;
  143.             inline bool operator!=(const ::FLAC__StreamMetadata *) const;
  144.             //@}
  145.  
  146.             friend class SimpleIterator;
  147.             friend class Iterator;
  148.  
  149.             /** Returns \c true if the object was correctly constructed
  150.              *  (i.e. the underlying ::FLAC__StreamMetadata object was
  151.              *  properly allocated), else \c false.
  152.              */
  153.             inline bool is_valid() const;
  154.  
  155.             /** Returns \c true if this block is the last block in a
  156.              *  stream, else \c false.
  157.              *
  158.              * \assert
  159.              *   \code is_valid() \endcode
  160.              */
  161.             bool get_is_last() const;
  162.  
  163.             /** Returns the type of the block.
  164.              *
  165.              * \assert
  166.              *   \code is_valid() \endcode
  167.              */
  168.             ::FLAC__MetadataType get_type() const;
  169.  
  170.             /** Returns the stream length of the metadata block.
  171.              *
  172.              * \note
  173.              *   The length does not include the metadata block header,
  174.              *   per spec.
  175.              *
  176.              * \assert
  177.              *   \code is_valid() \endcode
  178.              */
  179.             unsigned get_length() const;
  180.  
  181.             /** Sets the "is_last" flag for the block.  When using the iterators
  182.              *  it is not necessary to set this flag; they will do it for you.
  183.              *
  184.              * \assert
  185.              *   \code is_valid() \endcode
  186.              */
  187.             void set_is_last(bool);
  188.         private:
  189.             /** Private and undefined so you can't use it. */
  190.             Prototype();
  191.  
  192.             // These are used only by Iterator
  193.             bool is_reference_;
  194.             inline void set_reference(bool x) { is_reference_ = x; }
  195.         };
  196.  
  197.         inline bool Prototype::operator==(const Prototype &object) const
  198.         { return (bool)::FLAC__metadata_object_is_equal(object_, object.object_); }
  199.  
  200.         inline bool Prototype::operator==(const ::FLAC__StreamMetadata &object) const
  201.         { return (bool)::FLAC__metadata_object_is_equal(object_, &object); }
  202.  
  203.         inline bool Prototype::operator==(const ::FLAC__StreamMetadata *object) const
  204.         { return (bool)::FLAC__metadata_object_is_equal(object_, object); }
  205.  
  206.         inline bool Prototype::operator!=(const Prototype &object) const
  207.         { return !operator==(object); }
  208.  
  209.         inline bool Prototype::operator!=(const ::FLAC__StreamMetadata &object) const
  210.         { return !operator==(object); }
  211.  
  212.         inline bool Prototype::operator!=(const ::FLAC__StreamMetadata *object) const
  213.         { return !operator==(object); }
  214.  
  215.         inline bool Prototype::is_valid() const
  216.         { return 0 != object_; }
  217.  
  218.         /** Create a deep copy of an object and return it. */
  219.         FLACPP_API Prototype *clone(const Prototype *);
  220.  
  221.  
  222.         /** STREAMINFO metadata block.
  223.          *  See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>.
  224.          */
  225.         class FLACPP_API StreamInfo : public Prototype {
  226.         public:
  227.             StreamInfo();
  228.  
  229.             //@{
  230.             /** Constructs a copy of the given object.  This form
  231.              *  always performs a deep copy.
  232.              */
  233.             inline StreamInfo(const StreamInfo &object): Prototype(object) { }
  234.             inline StreamInfo(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  235.             inline StreamInfo(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  236.             //@}
  237.  
  238.             /** Constructs an object with copy control.  See
  239.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  240.              */
  241.             inline StreamInfo(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  242.  
  243.             ~StreamInfo();
  244.  
  245.             //@{
  246.             /** Assign from another object.  Always performs a deep copy. */
  247.             inline void operator=(const StreamInfo &object) { Prototype::operator=(object); }
  248.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  249.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  250.             //@}
  251.  
  252.             //@{
  253.             /** Check for equality, performing a deep compare by following pointers. */
  254.             inline bool operator==(const StreamInfo &object) const { return Prototype::operator==(object); }
  255.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  256.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  257.             //@}
  258.  
  259.             //@{
  260.             /** Check for inequality, performing a deep compare by following pointers. */
  261.             inline bool operator!=(const StreamInfo &object) const { return Prototype::operator!=(object); }
  262.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  263.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  264.             //@}
  265.  
  266.             //@{
  267.             /** See <A HREF="../format.html#metadata_block_streaminfo">format specification</A>. */
  268.             unsigned get_min_blocksize() const;
  269.             unsigned get_max_blocksize() const;
  270.             unsigned get_min_framesize() const;
  271.             unsigned get_max_framesize() const;
  272.             unsigned get_sample_rate() const;
  273.             unsigned get_channels() const;
  274.             unsigned get_bits_per_sample() const;
  275.             FLAC__uint64 get_total_samples() const;
  276.             const FLAC__byte *get_md5sum() const;
  277.  
  278.             void set_min_blocksize(unsigned value);
  279.             void set_max_blocksize(unsigned value);
  280.             void set_min_framesize(unsigned value);
  281.             void set_max_framesize(unsigned value);
  282.             void set_sample_rate(unsigned value);
  283.             void set_channels(unsigned value);
  284.             void set_bits_per_sample(unsigned value);
  285.             void set_total_samples(FLAC__uint64 value);
  286.             void set_md5sum(const FLAC__byte value[16]);
  287.             //@}
  288.         };
  289.  
  290.         /** PADDING metadata block.
  291.          *  See <A HREF="../format.html#metadata_block_padding">format specification</A>.
  292.          */
  293.         class FLACPP_API Padding : public Prototype {
  294.         public:
  295.             Padding();
  296.  
  297.             //@{
  298.             /** Constructs a copy of the given object.  This form
  299.              *  always performs a deep copy.
  300.              */
  301.             inline Padding(const Padding &object): Prototype(object) { }
  302.             inline Padding(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  303.             inline Padding(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  304.             //@}
  305.  
  306.             /** Constructs an object with copy control.  See
  307.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  308.              */
  309.             inline Padding(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  310.  
  311.             ~Padding();
  312.  
  313.             //@{
  314.             /** Assign from another object.  Always performs a deep copy. */
  315.             inline void operator=(const Padding &object) { Prototype::operator=(object); }
  316.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  317.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  318.             //@}
  319.  
  320.             //@{
  321.             /** Check for equality, performing a deep compare by following pointers. */
  322.             inline bool operator==(const Padding &object) const { return Prototype::operator==(object); }
  323.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  324.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  325.             //@}
  326.  
  327.             //@{
  328.             /** Check for inequality, performing a deep compare by following pointers. */
  329.             inline bool operator!=(const Padding &object) const { return Prototype::operator!=(object); }
  330.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  331.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  332.             //@}
  333.  
  334.             void set_length(unsigned length);
  335.         };
  336.  
  337.         /** APPLICATION metadata block.
  338.          *  See <A HREF="../format.html#metadata_block_application">format specification</A>.
  339.          */
  340.         class FLACPP_API Application : public Prototype {
  341.         public:
  342.             Application();
  343.             //
  344.             //@{
  345.             /** Constructs a copy of the given object.  This form
  346.              *  always performs a deep copy.
  347.              */
  348.             inline Application(const Application &object): Prototype(object) { }
  349.             inline Application(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  350.             inline Application(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  351.             //@}
  352.  
  353.             /** Constructs an object with copy control.  See
  354.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  355.              */
  356.             inline Application(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  357.  
  358.             ~Application();
  359.  
  360.             //@{
  361.             /** Assign from another object.  Always performs a deep copy. */
  362.             inline void operator=(const Application &object) { Prototype::operator=(object); }
  363.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  364.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  365.             //@}
  366.  
  367.             //@{
  368.             /** Check for equality, performing a deep compare by following pointers. */
  369.             inline bool operator==(const Application &object) const { return Prototype::operator==(object); }
  370.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  371.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  372.             //@}
  373.  
  374.             //@{
  375.             /** Check for inequality, performing a deep compare by following pointers. */
  376.             inline bool operator!=(const Application &object) const { return Prototype::operator!=(object); }
  377.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  378.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  379.             //@}
  380.  
  381.             const FLAC__byte *get_id() const;
  382.             const FLAC__byte *get_data() const;
  383.  
  384.             void set_id(const FLAC__byte value[4]);
  385.             //! This form always copies \a data
  386.             bool set_data(const FLAC__byte *data, unsigned length);
  387.             bool set_data(FLAC__byte *data, unsigned length, bool copy);
  388.         };
  389.  
  390.         /** SEEKTABLE metadata block.
  391.          *  See <A HREF="../format.html#metadata_block_seektable">format specification</A>.
  392.          */
  393.         class FLACPP_API SeekTable : public Prototype {
  394.         public:
  395.             SeekTable();
  396.  
  397.             //@{
  398.             /** Constructs a copy of the given object.  This form
  399.              *  always performs a deep copy.
  400.              */
  401.             inline SeekTable(const SeekTable &object): Prototype(object) { }
  402.             inline SeekTable(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  403.             inline SeekTable(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  404.             //@}
  405.  
  406.             /** Constructs an object with copy control.  See
  407.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  408.              */
  409.             inline SeekTable(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  410.  
  411.             ~SeekTable();
  412.  
  413.             //@{
  414.             /** Assign from another object.  Always performs a deep copy. */
  415.             inline void operator=(const SeekTable &object) { Prototype::operator=(object); }
  416.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  417.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  418.             //@}
  419.  
  420.             //@{
  421.             /** Check for equality, performing a deep compare by following pointers. */
  422.             inline bool operator==(const SeekTable &object) const { return Prototype::operator==(object); }
  423.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  424.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  425.             //@}
  426.  
  427.             //@{
  428.             /** Check for inequality, performing a deep compare by following pointers. */
  429.             inline bool operator!=(const SeekTable &object) const { return Prototype::operator!=(object); }
  430.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  431.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  432.             //@}
  433.  
  434.             unsigned get_num_points() const;
  435.             ::FLAC__StreamMetadata_SeekPoint get_point(unsigned index) const;
  436.  
  437.             //! See FLAC__metadata_object_seektable_set_point()
  438.             void set_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
  439.  
  440.             //! See FLAC__metadata_object_seektable_insert_point()
  441.             bool insert_point(unsigned index, const ::FLAC__StreamMetadata_SeekPoint &point);
  442.  
  443.             //! See FLAC__metadata_object_seektable_delete_point()
  444.             bool delete_point(unsigned index);
  445.  
  446.             //! See FLAC__metadata_object_seektable_is_legal()
  447.             bool is_legal() const;
  448.         };
  449.  
  450.         /** VORBIS_COMMENT metadata block.
  451.          *  See <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>.
  452.          */
  453.         class FLACPP_API VorbisComment : public Prototype {
  454.         public:
  455.             /** Convenience class for encapsulating Vorbis comment
  456.              *  entries.  An entry is a vendor string or a comment
  457.              *  field.  In the case of a vendor string, the field
  458.              *  name is undefined; only the field value is relevant.
  459.              *
  460.              *  A \a field as used in the methods refers to an
  461.              *  entire 'NAME=VALUE' string; the string is not null-
  462.              *  terminated and a length field is required since the
  463.              *  string may contain embedded nulls.
  464.              *
  465.              *  A \a field_name is what is on the left side of the
  466.              *  first '=' in the \a field.  By definition it is ASCII
  467.              *  and so is null-terminated and does not require a
  468.              *  length to describe it.  \a field_name is undefined
  469.              *  for a vendor string entry.
  470.              *
  471.              *  A \a field_value is what is on the right side of the
  472.              *  first '=' in the \a field.  By definition, this may
  473.              *  contain embedded nulls and so a \a field_value_length
  474.              *  is requires to describe it.
  475.              *
  476.              *  Always check is_valid() after the constructor or operator=
  477.              *  to make sure memory was properly allocated.
  478.              */
  479.             class FLACPP_API Entry {
  480.             public:
  481.                 Entry();
  482.                 Entry(const char *field, unsigned field_length);
  483.                 Entry(const char *field_name, const char *field_value, unsigned field_value_length);
  484.                 Entry(const Entry &entry);
  485.                 void operator=(const Entry &entry);
  486.  
  487.                 virtual ~Entry();
  488.  
  489.                 virtual bool is_valid() const;
  490.  
  491.                 unsigned get_field_length() const;
  492.                 unsigned get_field_name_length() const;
  493.                 unsigned get_field_value_length() const;
  494.  
  495.                 ::FLAC__StreamMetadata_VorbisComment_Entry get_entry() const;
  496.                 const char *get_field() const;
  497.                 const char *get_field_name() const;
  498.                 const char *get_field_value() const;
  499.  
  500.                 bool set_field(const char *field, unsigned field_length);
  501.                 bool set_field_name(const char *field_name);
  502.                 bool set_field_value(const char *field_value, unsigned field_value_length);
  503.             protected:
  504.                 bool is_valid_;
  505.                 ::FLAC__StreamMetadata_VorbisComment_Entry entry_;
  506.                 char *field_name_;
  507.                 unsigned field_name_length_;
  508.                 char *field_value_;
  509.                 unsigned field_value_length_;
  510.             private:
  511.                 void zero();
  512.                 void clear();
  513.                 void clear_entry();
  514.                 void clear_field_name();
  515.                 void clear_field_value();
  516.                 void construct(const char *field, unsigned field_length);
  517.                 void construct(const char *field_name, const char *field_value, unsigned field_value_length);
  518.                 void compose_field();
  519.                 void parse_field();
  520.             };
  521.  
  522.             VorbisComment();
  523.  
  524.             //@{
  525.             /** Constructs a copy of the given object.  This form
  526.              *  always performs a deep copy.
  527.              */
  528.             inline VorbisComment(const VorbisComment &object): Prototype(object) { }
  529.             inline VorbisComment(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  530.             inline VorbisComment(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  531.             //@}
  532.  
  533.             /** Constructs an object with copy control.  See
  534.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  535.              */
  536.             inline VorbisComment(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  537.  
  538.             ~VorbisComment();
  539.  
  540.             //@{
  541.             /** Assign from another object.  Always performs a deep copy. */
  542.             inline void operator=(const VorbisComment &object) { Prototype::operator=(object); }
  543.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  544.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  545.             //@}
  546.  
  547.             //@{
  548.             /** Check for equality, performing a deep compare by following pointers. */
  549.             inline bool operator==(const VorbisComment &object) const { return Prototype::operator==(object); }
  550.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  551.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  552.             //@}
  553.  
  554.             //@{
  555.             /** Check for inequality, performing a deep compare by following pointers. */
  556.             inline bool operator!=(const VorbisComment &object) const { return Prototype::operator!=(object); }
  557.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  558.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  559.             //@}
  560.  
  561.             unsigned get_num_comments() const;
  562.             Entry get_vendor_string() const; // only the Entry's field name should be used
  563.             Entry get_comment(unsigned index) const;
  564.  
  565.             //! See FLAC__metadata_object_vorbiscomment_set_vendor_string()
  566.             //! \note Only the Entry's field name will be used.
  567.             bool set_vendor_string(const Entry &entry);
  568.  
  569.             //! See FLAC__metadata_object_vorbiscomment_set_comment()
  570.             bool set_comment(unsigned index, const Entry &entry);
  571.  
  572.             //! See FLAC__metadata_object_vorbiscomment_insert_comment()
  573.             bool insert_comment(unsigned index, const Entry &entry);
  574.  
  575.             //! See FLAC__metadata_object_vorbiscomment_delete_comment()
  576.             bool delete_comment(unsigned index);
  577.         };
  578.  
  579.         /** CUESHEET metadata block.
  580.          *  See <A HREF="../format.html#metadata_block_cuesheet">format specification</A>.
  581.          */
  582.         class FLACPP_API CueSheet : public Prototype {
  583.         public:
  584.             /** Convenience class for encapsulating a cue sheet
  585.              *  track.
  586.              *
  587.              *  Always check is_valid() after the constructor or operator=
  588.              *  to make sure memory was properly allocated.
  589.              */
  590.             class FLACPP_API Track {
  591.             protected:
  592.                 ::FLAC__StreamMetadata_CueSheet_Track *object_;
  593.             public:
  594.                 Track();
  595.                 Track(const ::FLAC__StreamMetadata_CueSheet_Track *track);
  596.                 Track(const Track &track);
  597.                 void operator=(const Track &track);
  598.  
  599.                 virtual ~Track();
  600.  
  601.                 virtual bool is_valid() const;
  602.  
  603.                 inline FLAC__uint64 get_offset() const { return object_->offset; }
  604.                 inline FLAC__byte get_number() const { return object_->number; }
  605.                 inline const char *get_isrc() const { return object_->isrc; }
  606.                 inline unsigned get_type() const { return object_->type; }
  607.                 inline bool get_pre_emphasis() const { return object_->pre_emphasis; }
  608.  
  609.                 inline FLAC__byte get_num_indices() const { return object_->num_indices; }
  610.                 ::FLAC__StreamMetadata_CueSheet_Index get_index(unsigned i) const;
  611.  
  612.                 inline const ::FLAC__StreamMetadata_CueSheet_Track *get_track() const { return object_; }
  613.  
  614.                 inline void set_offset(FLAC__uint64 value) { object_->offset = value; }
  615.                 inline void set_number(FLAC__byte value) { object_->number = value; }
  616.                 void set_isrc(const char value[12]);
  617.                 void set_type(unsigned value);
  618.                 inline void set_pre_emphasis(bool value) { object_->pre_emphasis = value? 1 : 0; }
  619.  
  620.                  void set_index(unsigned i, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  621.                 //@@@ It's awkward but to insert/delete index points
  622.                 //@@@ you must use the routines in the CueSheet class.
  623.             };
  624.  
  625.             CueSheet();
  626.  
  627.             //@{
  628.             /** Constructs a copy of the given object.  This form
  629.              *  always performs a deep copy.
  630.              */
  631.             inline CueSheet(const CueSheet &object): Prototype(object) { }
  632.             inline CueSheet(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  633.             inline CueSheet(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  634.             //@}
  635.  
  636.             /** Constructs an object with copy control.  See
  637.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  638.              */
  639.             inline CueSheet(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  640.  
  641.             ~CueSheet();
  642.  
  643.             //@{
  644.             /** Assign from another object.  Always performs a deep copy. */
  645.             inline void operator=(const CueSheet &object) { Prototype::operator=(object); }
  646.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  647.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  648.             //@}
  649.  
  650.             //@{
  651.             /** Check for equality, performing a deep compare by following pointers. */
  652.             inline bool operator==(const CueSheet &object) const { return Prototype::operator==(object); }
  653.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  654.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  655.             //@}
  656.  
  657.             //@{
  658.             /** Check for inequality, performing a deep compare by following pointers. */
  659.             inline bool operator!=(const CueSheet &object) const { return Prototype::operator!=(object); }
  660.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  661.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  662.             //@}
  663.  
  664.             const char *get_media_catalog_number() const;
  665.             FLAC__uint64 get_lead_in() const;
  666.             bool get_is_cd() const;
  667.  
  668.             unsigned get_num_tracks() const;
  669.             Track get_track(unsigned i) const;
  670.  
  671.             void set_media_catalog_number(const char value[128]);
  672.             void set_lead_in(FLAC__uint64 value);
  673.             void set_is_cd(bool value);
  674.  
  675.             void set_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  676.  
  677.             //! See FLAC__metadata_object_cuesheet_track_insert_index()
  678.             bool insert_index(unsigned track_num, unsigned index_num, const ::FLAC__StreamMetadata_CueSheet_Index &index);
  679.  
  680.             //! See FLAC__metadata_object_cuesheet_track_delete_index()
  681.             bool delete_index(unsigned track_num, unsigned index_num);
  682.  
  683.             //! See FLAC__metadata_object_cuesheet_set_track()
  684.             bool set_track(unsigned i, const Track &track);
  685.  
  686.             //! See FLAC__metadata_object_cuesheet_insert_track()
  687.             bool insert_track(unsigned i, const Track &track);
  688.  
  689.             //! See FLAC__metadata_object_cuesheet_delete_track()
  690.             bool delete_track(unsigned i);
  691.  
  692.             //! See FLAC__metadata_object_cuesheet_is_legal()
  693.             bool is_legal(bool check_cd_da_subset = false, const char **violation = 0) const;
  694.         };
  695.  
  696.         /** Opaque metadata block for storing unknown types.
  697.          *  This should not be used unless you know what you are doing;
  698.          *  it is currently used only internally to support forward
  699.          *  compatibility of metadata blocks.
  700.          */
  701.         class FLACPP_API Unknown : public Prototype {
  702.         public:
  703.             Unknown();
  704.             //
  705.             //@{
  706.             /** Constructs a copy of the given object.  This form
  707.              *  always performs a deep copy.
  708.              */
  709.             inline Unknown(const Unknown &object): Prototype(object) { }
  710.             inline Unknown(const ::FLAC__StreamMetadata &object): Prototype(object) { }
  711.             inline Unknown(const ::FLAC__StreamMetadata *object): Prototype(object) { }
  712.             //@}
  713.  
  714.             /** Constructs an object with copy control.  See
  715.              *  Prototype(::FLAC__StreamMetadata *object, bool copy).
  716.              */
  717.             inline Unknown(::FLAC__StreamMetadata *object, bool copy): Prototype(object, copy) { }
  718.  
  719.             ~Unknown();
  720.  
  721.             //@{
  722.             /** Assign from another object.  Always performs a deep copy. */
  723.             inline void operator=(const Unknown &object) { Prototype::operator=(object); }
  724.             inline void operator=(const ::FLAC__StreamMetadata &object) { Prototype::operator=(object); }
  725.             inline void operator=(const ::FLAC__StreamMetadata *object) { Prototype::operator=(object); }
  726.             //@}
  727.  
  728.             //@{
  729.             /** Check for equality, performing a deep compare by following pointers. */
  730.             inline bool operator==(const Unknown &object) const { return Prototype::operator==(object); }
  731.             inline bool operator==(const ::FLAC__StreamMetadata &object) const { return Prototype::operator==(object); }
  732.             inline bool operator==(const ::FLAC__StreamMetadata *object) const { return Prototype::operator==(object); }
  733.             //@}
  734.  
  735.             //@{
  736.             /** Check for inequality, performing a deep compare by following pointers. */
  737.             inline bool operator!=(const Unknown &object) const { return Prototype::operator!=(object); }
  738.             inline bool operator!=(const ::FLAC__StreamMetadata &object) const { return Prototype::operator!=(object); }
  739.             inline bool operator!=(const ::FLAC__StreamMetadata *object) const { return Prototype::operator!=(object); }
  740.             //@}
  741.  
  742.             const FLAC__byte *get_data() const;
  743.  
  744.             //! This form always copies \a data
  745.             bool set_data(const FLAC__byte *data, unsigned length);
  746.             bool set_data(FLAC__byte *data, unsigned length, bool copy);
  747.         };
  748.  
  749.         /* \} */
  750.  
  751.  
  752.         /** \defgroup flacpp_metadata_level0 FLAC++/metadata.h: metadata level 0 interface
  753.          *  \ingroup flacpp_metadata
  754.          *
  755.          *  \brief
  756.          *  Level 0 metadata iterator.
  757.          *
  758.          *  See the \link flac_metadata_level0 C layer equivalent \endlink
  759.          *  for more.
  760.          *
  761.          * \{
  762.          */
  763.  
  764.          //! See FLAC__metadata_get_streaminfo().
  765.         FLACPP_API bool get_streaminfo(const char *filename, StreamInfo &streaminfo);
  766.  
  767.         /* \} */
  768.  
  769.  
  770.         /** \defgroup flacpp_metadata_level1 FLAC++/metadata.h: metadata level 1 interface
  771.          *  \ingroup flacpp_metadata
  772.          *
  773.          *  \brief
  774.          *  Level 1 metadata iterator.
  775.          *
  776.          *  The flow through the iterator in the C++ layer is similar
  777.          *  to the C layer:
  778.          *    - Create a SimpleIterator instance
  779.          *    - Check SimpleIterator::is_valid()
  780.          *    - Call SimpleIterator::init() and check the return
  781.          *    - Traverse and/or edit.  Edits are written to file
  782.          *      immediately.
  783.          *    - Destroy the SimpleIterator instance
  784.          *
  785.          *  The ownership of pointers in the C++ layer follows that in
  786.          *  the C layer, i.e.
  787.          *    - The objects returned by get_block() are yours to
  788.          *      modify, but changes are not reflected in the FLAC file
  789.          *      until you call set_block().  The objects are also
  790.          *      yours to delete; they are not automatically deleted
  791.          *      when passed to set_block() or insert_block_after().
  792.          *
  793.          *  See the \link flac_metadata_level1 C layer equivalent \endlink
  794.          *  for more.
  795.          *
  796.          * \{
  797.          */
  798.  
  799.         /** This class is a wrapper around the FLAC__metadata_simple_iterator
  800.          *  structures and methods; see ::FLAC__Metadata_SimpleIterator.
  801.          */
  802.         class FLACPP_API SimpleIterator {
  803.         public:
  804.             class FLACPP_API Status {
  805.             public:
  806.                 inline Status(::FLAC__Metadata_SimpleIteratorStatus status): status_(status) { }
  807.                 inline operator ::FLAC__Metadata_SimpleIteratorStatus() const { return status_; }
  808.                 inline const char *as_cstring() const { return ::FLAC__Metadata_SimpleIteratorStatusString[status_]; }
  809.             protected:
  810.                 ::FLAC__Metadata_SimpleIteratorStatus status_;
  811.             };
  812.  
  813.             SimpleIterator();
  814.             virtual ~SimpleIterator();
  815.  
  816.             bool init(const char *filename, bool read_only, bool preserve_file_stats);
  817.  
  818.             bool is_valid() const;
  819.             Status status();
  820.             bool is_writable() const;
  821.  
  822.             bool next();
  823.             bool prev();
  824.  
  825.             ::FLAC__MetadataType get_block_type() const;
  826.             Prototype *get_block();
  827.             bool set_block(Prototype *block, bool use_padding = true);
  828.             bool insert_block_after(Prototype *block, bool use_padding = true);
  829.             bool delete_block(bool use_padding = true);
  830.  
  831.         protected:
  832.             ::FLAC__Metadata_SimpleIterator *iterator_;
  833.             void clear();
  834.         };
  835.  
  836.         /* \} */
  837.  
  838.  
  839.         /** \defgroup flacpp_metadata_level2 FLAC++/metadata.h: metadata level 2 interface
  840.          *  \ingroup flacpp_metadata
  841.          *
  842.          *  \brief
  843.          *  Level 2 metadata iterator.
  844.          *
  845.          *  The flow through the iterator in the C++ layer is similar
  846.          *  to the C layer:
  847.          *    - Create a Chain instance
  848.          *    - Check Chain::is_valid()
  849.          *    - Call Chain::read() and check the return
  850.          *    - Traverse and/or edit with an Iterator or with
  851.          *      Chain::merge_padding() or Chain::sort_padding()
  852.          *    - Write changes back to FLAC file with Chain::write()
  853.          *    - Destroy the Chain instance
  854.          *
  855.          *  The ownership of pointers in the C++ layer is slightly
  856.          *  different than in the C layer, i.e.
  857.          *    - The objects returned by Iterator::get_block() are NOT
  858.          *      owned by the iterator and should be deleted by the
  859.          *      caller when finished, BUT, when you modify the block,
  860.          *      it will directly edit what's in the chain and you do
  861.          *      not need to call Iterator::set_block().  However the
  862.          *      changes will not be reflected in the FLAC file until
  863.          *      the chain is written with Chain::write().
  864.          *    - When you pass an object to Iterator::set_block(),
  865.          *      Iterator::insert_block_before(), or
  866.          *      Iterator::insert_block_after(), the iterator takes
  867.          *      ownership of the block and it will be deleted by the
  868.          *      chain.
  869.          *
  870.          *  See the \link flac_metadata_level2 C layer equivalent \endlink
  871.          *  for more.
  872.          *
  873.          * \{
  874.          */
  875.  
  876.         /** This class is a wrapper around the FLAC__metadata_chain
  877.          *  structures and methods; see ::FLAC__Metadata_Chain.
  878.          */
  879.         class FLACPP_API Chain {
  880.         public:
  881.             class FLACPP_API Status {
  882.             public:
  883.                 inline Status(::FLAC__Metadata_ChainStatus status): status_(status) { }
  884.                 inline operator ::FLAC__Metadata_ChainStatus() const { return status_; }
  885.                 inline const char *as_cstring() const { return ::FLAC__Metadata_ChainStatusString[status_]; }
  886.             protected:
  887.                 ::FLAC__Metadata_ChainStatus status_;
  888.             };
  889.  
  890.             Chain();
  891.             virtual ~Chain();
  892.  
  893.             friend class Iterator;
  894.  
  895.             bool is_valid() const;
  896.             Status status();
  897.  
  898.             bool read(const char *filename);
  899.             bool write(bool use_padding = true, bool preserve_file_stats = false);
  900.  
  901.             void merge_padding();
  902.             void sort_padding();
  903.  
  904.         protected:
  905.             ::FLAC__Metadata_Chain *chain_;
  906.             virtual void clear();
  907.         };
  908.  
  909.         /** This class is a wrapper around the FLAC__metadata_iterator
  910.          *  structures and methods; see ::FLAC__Metadata_Iterator.
  911.          */
  912.         class FLACPP_API Iterator {
  913.         public:
  914.             Iterator();
  915.             virtual ~Iterator();
  916.  
  917.             bool is_valid() const;
  918.  
  919.             void init(Chain &chain);
  920.  
  921.             bool next();
  922.             bool prev();
  923.  
  924.             ::FLAC__MetadataType get_block_type() const;
  925.             Prototype *get_block();
  926.             bool set_block(Prototype *block);
  927.             bool delete_block(bool replace_with_padding);
  928.             bool insert_block_before(Prototype *block);
  929.             bool insert_block_after(Prototype *block);
  930.  
  931.         protected:
  932.             ::FLAC__Metadata_Iterator *iterator_;
  933.             virtual void clear();
  934.         };
  935.  
  936.         /* \} */
  937.  
  938.     };
  939. };
  940.  
  941. #endif
  942.